INCLUDE(FindPackageHandleStandardArgs)
INCLUDE(HandleLibraryTypes)

SET(OPENGL_IncludeSearchPaths
  /usr/include/GL/
  /opt/local/include/GL/
)
SET(GLEW_IncludeSearchPaths
  /usr/include/GL/
  /opt/local/include/GL/
)

SET(OPENGL_LibrarySearchPaths
  /usr/lib/
  /opt/local/lib/
)
SET(GLEW_LibrarySearchPaths
  /usr/lib/
  /opt/local/lib/
)

FIND_PATH(OPENGL_INCLUDE_DIR
  NAMES gl.h glu.h
  PATHS ${OPENGL_IncludeSearchPaths}
)
FIND_PATH(GLEW_INCLUDE_DIR
  NAMES glew.h
  PATHS ${GLEW_IncludeSearchPaths}
)

FIND_LIBRARY(OPENGL_LIBRARY_OPTIMIZED
  NAMES glut
  PATHS ${OPENGL_LibrarySearchPaths}
)
FIND_LIBRARY(GLEW_LIBRARY_OPTIMIZED
  NAMES GLEW
  PATHS ${GLEW_LibrarySearchPaths}
)

# Handle the REQUIRED argument and set the <UPPERCASED_NAME>_FOUND variable
# The package is found if all variables listed are TRUE
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OPENGL "Could NOT find OpenGL library, did you install 'freeglut3' and 'freeglut3-dev'?"
  OPENGL_LIBRARY_OPTIMIZED
  OPENGL_INCLUDE_DIR
)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLEW "Could NOT find glew library, did you install 'libglew-dev'?"
  GLEW_LIBRARY_OPTIMIZED
  GLEW_INCLUDE_DIR
)


# Collect optimized and debug libraries
HANDLE_LIBRARY_TYPES(OPENGL)
HANDLE_LIBRARY_TYPES(GLEW)

MARK_AS_ADVANCED(
  OPENGL_INCLUDE_DIR
  OPENGL_LIBRARY_OPTIMIZED
  GLEW_INCLUDE_DIR
  GLEW_LIBRARY_OPTIMIZED
)
